package com.zsh.spring.test;

import com.zsh.spring.entity.Book;
import com.zsh.spring.service.BookService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class test {
    @Test
    public void testJdbcTem1(){
        Object object;
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        Book book = new Book();
        book.setId(1);
        book.setName("java");
        book.setStatus("a");
        bookService.addBook(book);
    }

    @Test
    public void testJdbcTem2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);
        Book book = new Book();
        book.setId(1);
        book.setName("c++");
        book.setStatus("b");
        bookService.updateBook(book);

    }

    @Test
    public void testJdbcTem3(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);

        bookService.deleteBook(1);
    }

    @Test
    public void testJdbcTem4(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);

        int i = bookService.queryCount();
        System.out.println(i);
    }

    @Test
    public void testJdbcTem5(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);

        Book book = bookService.queryOneBook(1);

        System.out.println(book);
    }

    @Test
    public void testJdbcTem6(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);

        List<Book> books = bookService.queryAllBooks();

        System.out.println(books);
    }

    @Test
    public void testJdbcTem7(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        BookService bookService = context.getBean("bookService", BookService.class);

        List<Object[]> list = new ArrayList<>();
        Object[] o1 = {5,"jdk","a"};
        Object[] o2 = {6,"jdk2","a"};
        Object[] o3 = {7,"jdk3","a"};
        list.add(o1);
        list.add(o2);
        list.add(o3);
        bookService.batchAdd(list);

    }
}
